package controller;

import java.awt.Frame;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.TreeMap;
import java.util.TreeSet;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import model.kwalificatiebeheer.Kerntaak;
import model.kwalificatiebeheer.Uitstroomrichting;
import model.kwalificatiebeheer.Werkproces;

import view.KerntaakPanel;
import view.KwalificatieDossierPanel;
import view.WerkprocesPanel;

public class WerkprocesTableActions implements MouseListener {
	private KerntaakPanel sender;
	private JTable kttable;
	
	public WerkprocesTableActions(KerntaakPanel sender, JTable kttable) {
		this.sender = sender;
		this.kttable = kttable;
	}
	
	@Override
	public void mousePressed(MouseEvent e) {
		if (e.getClickCount() == 2) {
			TreeMap<Uitstroomrichting, TreeSet<Werkproces>> wpList = sender.getKerntaak().getUitstroomWerkprocessen();
			ArrayList<Uitstroomrichting> urList = new ArrayList<Uitstroomrichting>(wpList.keySet());
			int ur = urList.get(kttable.getSelectedColumn()).getId();
			ArrayList<Werkproces> wps = new ArrayList<Werkproces>(wpList.get(new Uitstroomrichting(ur)));
			Werkproces wp = wps.get(kttable.getSelectedRow());
			
			JFrame ktFrame = new JFrame();
			ktFrame.setTitle("Werkproces: "+wp.getTitel());
			ktFrame.getContentPane().add(new JScrollPane(new WerkprocesPanel(wp)));
			ktFrame.setSize(1500,1000);
			ktFrame.setExtendedState(Frame.MAXIMIZED_BOTH);
			ktFrame.setVisible(true);				
			ktFrame.setLocationRelativeTo(null);
		}
	}
	
	@Override
	public void mouseClicked(MouseEvent e) {
		
	}
	
	@Override
	public void mouseEntered(MouseEvent e) {}
	@Override
	public void mouseExited(MouseEvent e) {}
	@Override
	public void mouseReleased(MouseEvent e) {}

}
